import asyncio
import logging
from aiogram import Bot, Dispatcher, types
from aiogram.filters.command import Command
from app.handlers import setup as setup_handlers

from config.config import BOT_MODE, BOT_TOKEN

#TODO make bot with tutorial https://www.youtube.com/playlist?list=PLe-iIMbo5JOLhnbNXP7V7u_N0m07iqe9e

#TODO вынести логер в отдельный модуль?
# ========== LOGGER ==============
LOG_FORMAT = "%(asctime)s %(levelname)s %(name)s - %(message)s"
logging.basicConfig(
		#filename="program.log",
		level=logging.INFO if BOT_MODE == 'prod' else logging.DEBUG,
		format=LOG_FORMAT)
logger = logging.getLogger(__name__)

logging.getLogger("aiogram").setLevel(logging.DEBUG + 1)
# =======================================

# ====== Bot =============
bot = Bot(token=BOT_TOKEN)
dp = Dispatcher()
# ========================


async def main():
    logger.info(f"Bot has been started in {BOT_MODE.upper()} MODE")
    setup_handlers(dp)
    await dp.start_polling(bot)


if __name__ == "__main__":
    try:
        asyncio.run(main())
    except Exception:
        logger.exception('Main exception')
    finally:
        pass
